<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button @click="fn1">按钮</button>
      <p>{{ msg }}</p>
    </div>

    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data() {
            return {
                msg: 'hello',
                age: 19
            }
        },
        methods: {
          fn1 () {
            // 得到当前vue实例（vue对象）
            console.log(this)
            // 在某个阶段的时候，会自动把data和methods里的内容全部挂载到当前实例的最外层
            console.log(this.msg)
            console.log(this.age)
            // console.log(this.data.msg) // 访问不了,会报错
            this.test()

            this.msg = '你坏'
          },

          test () {
            console.log('test被调用')
          }
        }
      })

    </script>
  </body>
</html>
